﻿
using GameServer.Network;
using System.Net;
using System.Net.Sockets;
using System.Text;
using Summer.Network;
using Proto;
using Common;
using Serilog;
using GameServer.Service;
using GameServer.Mgr;
using GameServer.Model;
using GameServer.Database;
using System.Data.SqlTypes;
using Summer;
using GameServer.AI;

namespace GameServer
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //初始化日志环境
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Debug() //debug , info , warn , error
                .WriteTo.Async(a=>a.Console())
                .WriteTo.Async(a => a.File("logs\\server-log.txt", rollingInterval: RollingInterval.Day))
                .CreateLogger();

            DataManager.Instance.Init();


            //网路服务模块
            NetService netService = new NetService();
            netService.Start();
            Log.Debug("网络服务启动完成");

            UserService userService = UserService.Instance;
            userService.Start();
            Log.Debug("玩家服务启动完成");

            SpaceService spaceService = SpaceService.Instance;
            spaceService.Start();
            Log.Debug("地图服务启动完成");

            Scheduler.Instance.Start();
            Log.Debug("中心计时启动完成");

            ChatService.Instance.Start();
            Log.Debug("聊天服务启动完成");


            
            
            //Monster monster = space.monsterManager.Create(1001,1001,new Vector3Int(-1758, 0, 62912),new Vector3Int(0,0,0));
            //space.monsterManager.Create(1002, 1002, new Vector3Int(-1755, 0, 64912), new Vector3Int(0, 0, 0));
            //monster.AI = new MonsterAI(monster);


            Scheduler.Instance.AddTask(() =>
            {
                EntityManager.Instance.Update();
                SpaceManager.Instance.Update();
            },0.02f);

            //string exePath=System.Reflection.Assembly.GetExecutingAssembly().Location;

            //string exeDirectory=Path.GetDirectoryName(exePath);
            //Log.Debug(exeDirectory);
            //string txtFilePath = Path.Combine(exeDirectory, @"Data/SpaceDefine.json");

            //string content = File.ReadAllText(txtFilePath);

            //Console.WriteLine(content);

            //Db.fsql.Insert(new DbPlayer()).ExecuteAffrows();
            //Db.fsql.Insert(new DbCharacter()).ExecuteAffrows();
            //Db.fsql.Insert(new DbPossessSkill()).ExecuteAffrows();
            //Db.fsql.Insert(new DbUsingSkill()).ExecuteAffrows();
            //Truncate mmodb.character


            while (true)
            {
                Thread.Sleep(100);
            }
        }

        
    }
}